// call 将一个函数强行绑定到一个对象身上

function foo(x) {
  console.log(this.a, x);
}

const obj = {
  a: 1
}

foo.call(obj, 3)   // 1 3

Function.prototype.myCall = function (...args) {
  const context = args[0]
  const arg = args.splice(1)
  context.fn = this
  const res = context.fn(...arg)
  delete context.fn
  return res
}

foo.myCall(obj, 3)